package slice

// DiffSet 求两个切片的差集, 已去重
func DiffSet[T comparable](src []T, dst []T) []T {
	srcMap := ToMap(src)
	for _, valDst := range dst {
		delete(srcMap, valDst)
	}
	var ret = make([]T, 0, len(srcMap))
	for key := range srcMap {
		ret = append(ret, key)
	}
	return ret
}

// DiffSetFunc 自定义去重方式
func DiffSetFunc[T comparable](src, dst []T, equal func(src, dst T) bool) []T {
	var ret = make([]T, 0, len(src))
	for _, v := range src {
		if !ContainsFunc(dst, func(src T) bool {
			return equal(src, v)
		}) {
			ret = append(ret, v)
		}
	}
	return Nodup(ret)
}
